package com.dao.impl;

import com.dao.UserDao;
import com.entry.User;
import com.util.DBHelper;


import java.util.ArrayList;


public class UserDaoImpl implements UserDao {

   private DBHelper db = new DBHelper();

    @Override
    public ArrayList<User> selectAll() {
        String sql = "select * from book";
        return db.query(sql, User.class);
    }

//    @Override
//    public ArrayList<User> selectQuery(User book) {
//        StringBuilder sql =new StringBuilder("select * from book where 1=1 ");
//        if(book.getBookName()!=null){
//            sql.append( "and BOOKNAME like ?");
//            return db.query(sql.toString(), User.class,"%"+book.getBookName()+"%");
//        }else if(book.getBookAuthor()!=null){
//            sql.append( "and BOOKAUTHOR like ?");
//            return db.query(sql.toString(), User.class,"%"+book.getBookAuthor()+"%");
//        }else if(book.getBookPublish()!=null){
//            sql.append( "and BOOKPUBLISH like ?");
//            return db.query(sql.toString(), User.class,"%"+book.getBookPublish()+"%");
//        }else{
//            return db.query(sql.toString(), User.class);
//        }
//    }
//
//    @Override
//    public boolean insertBook(User book) {
//        String sql="insert into book (BOOKNAME,BOOKAUTHOR,BOOKPUBLISH,BOOKPAGE,BOOKPRICE,CREATEDATE) " +
//                "values(?,?,?,?,?,current_date())";
//       int i= db.updateTable(sql,book.getBookName(),book.getBookAuthor(),book.getBookPublish(),book.getBookPage(),book.getBookPrice());
//       return i==1?true:false;
//    }
//
//    @Override
//    public boolean deleteBook(int bid) {
//
//        String sql="delete from book where BOOKID=?";
//
//        return db.updateTable(sql,bid)>0?true:false;
//
//    }
//
//    @Override
//    public User selectById(int bid) {
//        String sql="select * from book where  BOOKID=? ";
//        return (User)(db.query(sql, User.class,bid).get(0));
//    }
//
//    @Override
//    public boolean updateBook(User book) {
//        String sql="update book set BOOKNAME=?,BOOKAUTHOR=?,BOOKPUBLISH=?,BOOKPAGE=?,BOOKPRICE=?,CREATEDATE=?  where BOOKID=?";
//        Object[] objs={book.getBookName(),book.getBookAuthor(),book.getBookPublish(),book.getBookPage(),book.getBookPrice(),book.getCreateDate(),book.getBookId()};
//        return db.updateTable(sql,objs)>0?true:false;
//    }
}
